package com.sx.gongzhong.adapter;


import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.MyApplication;
import com.sx.gongzhong.R;
import com.sx.gongzhong.activity.ExposureDetailActivity;
import com.sx.gongzhong.model.CommentBean;
import com.sx.gongzhong.net.ServiceFactory;
import com.sx.gongzhong.utils.BaseUtil;

import java.util.List;

/**
 * Created by XZY on 2017/12/28
 * 爆料的评论列表
 */

public class ExposureReplyAdapter extends BaseQuickAdapter<CommentBean,BaseViewHolder> {

    private Context context;

    public ExposureReplyAdapter(Context context, @LayoutRes int layoutResId,
                                @Nullable List<CommentBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, CommentBean item) {
        if (item.getReplyUser() != null && !BaseUtil.isEmpty(item.getReplyUser().getHeaderUrl())){
            Glide.with(context).load(ServiceFactory.getUrl(item.getReplyUser().getHeaderUrl()))
                    .apply(new RequestOptions().centerCrop().circleCrop().
                            placeholder(R.mipmap.img_head_58).error(R.mipmap.img_head_58))
                    .into((ImageView) helper.getView(R.id.im_Head));
        }
        helper.setText(R.id.tv_Name,item.getReplyUser()!=null?item.getReplyUser().getName():"");
        helper.setText(R.id.tv_Time,item.getReplyTime());
        helper.setText(R.id.tv_Content,item.getContent());
        TextView tv_Report=helper.getView(R.id.tv_Report);
        TextView tvShutUp= helper.getView(R.id.tv_ShutUp);
        TextView tv_Delete= helper.getView(R.id.tv_Delete);
        if (MyApplication.instance.userBean!=null) {
            tv_Report.setOnClickListener(new MyClickListener(item));
            tvShutUp.setOnClickListener(new MyClickListener(item));
            tv_Delete.setOnClickListener(new MyClickListener(item));
            if ("general".equalsIgnoreCase(MyApplication.instance.userBean.userType.code)) {//普通用户
                tvShutUp.setVisibility(View.GONE);
                if (item.getReplyUser()!= null && !item.getReplyUser().getId().equals(MyApplication.instance.userBean.id)) {
                    tv_Delete.setVisibility(View.GONE);
                } else {
                    tv_Delete.setVisibility(View.VISIBLE);
                }
            }
        }
    }

   private class MyClickListener implements View.OnClickListener{

        private CommentBean replyBean;

        private MyClickListener(CommentBean replyBean) {
            this.replyBean=replyBean;
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.tv_ShutUp:
                    ((ExposureDetailActivity)context).createReport("forbiddenType",
                            replyBean.getId(),"选择禁言时间","broke_news_reply");
                    break;
                case R.id.tv_Report:
                    ((ExposureDetailActivity)context).createReport("reportType",
                            replyBean.getId(),"选择举报类型","broke_news_reply");
                    break;
                case R.id.tv_Delete://删除
                    ((ExposureDetailActivity)context).createDialog(replyBean.getId(),2);
                    break;
            }
        }
    }

}
